<?php include("head.php");
     // include_once("paging_function.php");
include_once("watermark_funpast.php");
$randNumber=rand(10000,99999);

$sql1="select * from ".SITEBANNER." ";

 $query1=mysql_query($sql1);
 $countrow=mysql_num_rows($query1);
 $fetch=mysql_fetch_array($query1);

if($fetch['bannerImage']=='' || !file_exists('banner_image_thumb/'.$fetch['bannerImage']))
				$bannerimagePath = '<img border="0" src="banner_image/no_image.jpg" height="81px" width="482px" />';
			else
				$bannerimagePath = '<img border="0" src="banner_image_thumb/'.$fetch['bannerImage'].'" height="81px" width="482px"/>';

if(isset($_POST['Submit']) && $_POST['Submit'] == 'Edit')
{
		//==========================================value asigin==========================================================//

			 $id=$_REQUEST['id'];
			 $bUrl=$_POST['url'];
			 
	
	//--------------------------------------database update-----------------------------------------------------------//
	
		mysql_query("update ".SITEBANNER." set bannerUrl='".$bUrl."' where bannerId='".$id."'");
		if(!empty($_FILES['pic']['name']))
		{
		$filepath_image=$_FILES['pic']['name'];
		//print_r( $filepath_image);
		$target_path_image="banner_image/";
		$target_path1_image=$target_path_image.$filepath_image;
		$rt_image=explode(".",$filepath_image);
		
		$cou_image=count($rt_image);
		//echo $cou_image;
		echo $ext_image=strtolower($rt_image[$cou_image-1]);
		
		$imagename = "pic".$randNumber.$ext_image;
		
		$destPathImage="banner_image/".$imagename;


		if($_FILES['pic']['name']!='')
				{
		if($ext_image=='jpg' || $ext_image=='gif' || $ext_image=='png')
		{	
			move_uploaded_file($_FILES['pic']['tmp_name'],$destPathImage);
			watermark_funpast($imagename,"banner_image","banner_image_thumb",'81px','482px');
		}
				}
		$sql_viewimage=mysql_query("update ".SITEBANNER." set bannerImage='".$imagename."' where bannerId='".$id."'");
		}

	echo '<script>window.location="banner_management.php?action=show&id='.$id.'&a=done"</script>';
//=====================================value define=======================================================//
   
 }
if(isset($_POST['Submit']) && $_POST['Submit'] == 'Insert')
{

	$bUrl=$_POST['url'];
	
	//////////////////////////insert into database/////////////////////////////////////
		if($countrow==0)
		{
		$exeQuery=mysql_query("insert into ".SITEBANNER." set bannerUrl='".$bUrl."' ") or die(mysql_error());
		
		$i=mysql_insert_id();
		}
		else
		{
		mysql_query("update ".SITEBANNER." set bannerUrl='".$bUrl."' where bannerId='".$_REQUEST['id']."'");
		}
		
		$filepath_image=$_FILES['pic']['name'];
		//print_r( $filepath_image);
		$target_path_image="banner_image/";
		echo $target_path1_image=$target_path_image.$filepath_image;
		$rt_image=explode(".",$filepath_image);
		
		$cou_image=count($rt_image);
		//echo $cou_image;
		echo $ext_image=strtolower($rt_image[1]);
		
		$imagename = "pic".$randNumber.$ext_image;
		//echo $imagename;
		$destPathImage="banner_image/".$imagename;


		if($_FILES['pic']['name']!='')
				{
		if($ext_image=='jpg' || $ext_image=='gif' || $ext_image=='png')
		{	
			move_uploaded_file($_FILES['pic']['tmp_name'],$destPathImage);
			watermark_funpast($imagename,"banner_image","banner_image_thumb",'81px','482px');
		}
				}
		$sql_viewimage=mysql_query("update ".SITEBANNER." set bannerImage='".$imagename."' ");
		
		

	//echo '<script>window.location="banner_management.php?a=insert"</script>';

}
 
 
 
 
//===========================================delete==============================================================
if(isset($_REQUEST['submit1']))
   {
$id=$_REQUEST['del'];

for($i=0;$i<count($id);$i++)
      {
       $sql="delete  from ".SITEBANNER." where bannerId='".$id[$i]."'";
       mysql_query($sql);
        echo '<script>window.location="banner_management.php?a=del"</script>';
      }

    }
?>
<?php


$db = mysql_query("SELECT * FROM ".GLOBALSETTINGS);
$fet = mysql_fetch_array($db);
$lim=$adminpagelimit;
?>
<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {

id =0;
eval("page" + id + " = window.open(URL, '" + id + "', 'status=0,toolbar=0,menubar=0,resizable=0,dependent=0,width=400,height=400,left=25,top=25');");
}
</script>

<script language="javascript">
function valid()
{
if(document.banner.faq.value.search(/\S/)==-1)
    {
    alert("Please Enter Your Question");
    document.banner.faq.focus();
    return false;
    }
if(document.banner.answer.value=="")
        {
          alert("Enter Your Answer...");
          document.banner.answer.focus();
          return false;
        }
        return true;
}
</script>


<fieldset>

	<legend class="LEGEND"><strong>Upload Banner</strong></legend>
		<table width="100%">
		<tr><td>
		<table width="100%" align="center" >
		<tr>
		<td>
		
		<form name="banner" action="" method="POST" onsubmit="return valid()" enctype="multipart/form-data">
		
		<table width="550" border="0" cellspacing="0" cellpadding="0" align="left">
				<tr>
				<td align="left" valign="top" class="signin_tlgap" colspan="3"><b>upload Banner Image Here.</b></td>
			  </tr>
		<?php $msg=$_REQUEST['a'];
			  
			  if($msg == 'insert')
			   {?>
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully insert</font></td>
		</tr>  
		<?php  }?>
		<?php //$msg=$_REQUEST['del'];
			  if($msg == 'del')
			   {?>
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully delete</font></td>
		</tr>  
		<?php      }
			  elseif($msg == 'done') 
			{
		?> 
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully edit</font></td>
		</tr>  
		  <?php
		  	}
		  ?>
			  <tr>
				<td align="left" valign="top" class="signin_tlgap" colspan="2">&nbsp;</td>
				<td align="left" valign="top" class="refer_rgap">&nbsp;</td>
			  </tr>
		
				  <tr>
					<td align="left" valign="top" class="con_tlcon"><strong>Banner Link</strong></td>
					<td align="left" valign="top"><input type="text" name="url" value="<?php if($_REQUEST['action']=='show')echo $fetch['bannerUrl'];?>" size="<?php if($fetch['bannerUrl'] != '') echo $fetch['bannerUrl']; else echo "No Link"; ?>"></td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  <tr>
					<td align="left" valign="top" class="con_tlcon">&nbsp;</td>
					<td align="left" valign="top" class="con_box">&nbsp;</td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  <tr>
					<td align="left" valign="top" class="con_tlcon"><strong>Banner Image</strong></td>
					<td align="left" valign="top" class="con_box"><input type="file" name="pic" /></td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  
				  <tr>
					<td align="left" valign="top" class="con_tlcon">&nbsp;</td>
					<td align="left" valign="top" class="con_box"><span class="con_rgap">
					  <input type="submit" name="Submit" value="<?php if($_REQUEST['action']=='show'){echo 'Edit';}else echo 'Insert';?>" />
					</span><?php if($_REQUEST['action']=='show'){?><input type="button" value="Back"  onClick="javascript:window.location='banner_management.php';" name="back"><?php } ?>
							</td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				 </tr>
			  </table>
		</form>
		
		
		</td></tr>
		
		<?php   //---------------------------------query to show the form----------------------------------------------//
		#echo FAQ.'<br><br>';
		$sql1="select * from ".SITEBANNER." order by bannerId desc ";
		
		#echo $sql1.'<br>';
		$show=mysql_query($sql1);
		#echo mysql_field_name($show,1);
		//print_r();
		?>
		<?php
		
		while($fetch=mysql_fetch_array($show))
			{
		 ?>
		 <tr>
		   <td>&nbsp;</td>
		 </tr>
		 <tr><td>
		<form name="show" action="" method="POST" enctype="multipart/form-data">
		   <table width="100%" border="0" cellspacing="2" cellpadding="2" align="left" >
			  <tr>
			  <td>
				 <table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#F5F2FF">
				   <tr bgcolor="#A2AFDF" >
					<td align="center" valign="middle" width="80" height="30"><strong>Banner Link: </strong></td>
					<td align="left" valign="middle"  class="con_box"><?php echo $fetch['bannerUrl'];?></td>
				   </tr>
				   
				   <tr>
					<td align="center" valign="middle" width="80" height="30" ><strong>Banner Image: </strong></td>
					<td><?php echo $bannerimagePath;?></td>
					</tr>
				  <tr>
					<td>&nbsp;</td>
					<td align="right"><a href="banner_management.php?action=show&id=<?php echo $fetch['bannerId'];?>" ><img src="images/edit_icon.gif" border="0"/></a>&nbsp;&nbsp;&nbsp;<input type="checkbox" value="<?php echo  $fetch['bannerId'];?> "  name="del[]"/>&nbsp;&nbsp;<input type="submit" name="submit1" value="delete"></td>
				  </tr>
				  </table>
			   </td>
			  </tr>
		   </table>
		</form></td></tr>
		<?php } ?>
		
		
		<TR>
		<TD align="center"><?php #echo paging($sql1,$page,$limit,'');?></TD>
		</TR>
		</table>
		</td></tr>
		</table>
</fieldset>	  
	  
	  
<?php
include_once("foot.php");
?>